<template>
<el-card :body-style="{padding: '0px'}" class="relative">
  <div v-if="self" slot="header" class="clearfix">
      <div class="f5 tc">{{dateFormat(item.create_time).format('YYYY-MM-DD HH:mm:ss')}}</div>
    <div class="fr mb2">
      <el-tag class="ml1" v-for="tag in item.tags" v-bind:key="tag" type="success" size="small">{{tag}}</el-tag>
    </div>
  </div>
  <div v-if="!self" slot="header" class="clearfix">
    <span>
      {{item.creator.nickname}}
      <span class="moon-gray f7 ml3">{{dateFormat(item.create_time).format('YYYY-MM-DD HH:mm:ss')}}</span>
    </span>
    <div class="fr mb2">
      <el-tag class="ml1" v-for="tag in item.tags" v-bind:key="tag" type="success" size="small">{{tag}}</el-tag>
    </div>
  </div>
  <article class="pa4">
    <router-link :to="`/home/article/${item.id}`" class="db pv1 ph3 ph0-l no-underline black dim" href="#0">
      <div class="flex flex-column flex-row-ns">
        <div v-if="item.pictures.length > 0" class="pr3-ns mb4 mb0-ns w-100 w-50-ns relative">
          <img :src="item.pictures[0]" class="db" :alt="item.creator.nickname + '的图片分享'">
          <div class="absolute right-2 bottom-1 br2 f6 tc white piclen ">{{item.pictures.length}}</div>
        </div>
        <div class="w-100 w-50-ns pl3-ns">
          <p class="f6 f5-l lh-copy">
            {{item.article}}
          </p>
        </div>
      </div>
    </router-link>
  </article>
  <div class="absolute bottom-0 right-2">
    <router-link :to="`/home/article/${item.id}`">
      <el-badge :value="item.comments" class="item">
        <el-button type="text" class="pa0"><i class="material-icons v-mid f4">comment</i><span class="v-mid  f7">评论</span></el-button>
      </el-badge>
    </router-link>
    <like :articleId="item.id" :count="item.likeCount" :like="item.like" />
  </div>
</el-card>
</template>

<script>
import Like from '@/components/Like';
import moment from 'moment';

export default {
  name: 'ArticleContent',
  props: ['item', 'self'],
  data() {
    return {};
  },
  methods: {
    dateFormat: moment,
  },
  components: {
    Like,
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.persion-box {
  margin: 20px auto;
}

.text-over {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.piclen {
  width: 40px;
  height: 20px;
  line-height: 20px;
  background: rgba(0, 0, 0, .7);
  box-shadow: #fff 0 0 2px;
}

.pa0 {
  padding: 0;
}
</style>

